import Vue from 'vue';
import App from './App';
import router from './router';
import axios from 'axios';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import VueAMap from 'vue-amap';

Vue.use(ElementUI);
Vue.use(VueAMap);

Vue.config.productionTip = false;

Vue.prototype.$http = axios;
<<<<<<< .mine
axios.defaults.baseURL = "http://192.168.0.110:9001";
=======
axios.defaults.baseURL = "http://192.168.1.100:9001";
>>>>>>> .theirs

// 初始化高德地图
VueAMap.initAMapApiLoader({
  key: '37dcbf94855d075a37336307ffdb7e23', // 替换成你的高德地图 API Key
  plugin: [
    'AMap.Autocomplete',
    'AMap.PlaceSearch',
    'AMap.Scale',
    'AMap.OverView',
    'AMap.ToolBar',
    'AMap.MapType',
    'AMap.PolyEditor',
    'AMap.CircleEditor'
  ],
  v: '1.4.15'
});

// 添加请求拦截器
axios.interceptors.request.use(req => {
<<<<<<< .mine
  req.baseURL = "http://192.168.0.110:9001";
=======
  req.baseURL = "http://192.168.1.100:9001";
>>>>>>> .theirs
  let token = localStorage.getItem("token");
  if (token) {
    req.headers.token = token;
  }
  return req;
});

//添加响应拦截器（根据需要取消注释）
axios.interceptors.response.use(resp => {
  if (resp.data.code == 401) {
    alert("401!!!");
    router.push("/Home");
  }

  if (resp.data.code == 403) {
    router.push("/busy");
  }
  if (resp.data.code == 200) {
    let token = resp.headers.get("token");
	// console.log(token)
    if (token) {
      localStorage.setItem("token", token);
      localStorage.setItem("id", resp.data.data.accountId);
      localStorage.setItem("stationId", resp.data.data.stationId);
    }
  }

  return resp;
});

new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
});
